package org.jeecg.modules.demo.zhengchai.household.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.demo.zhengchai.household.entity.Household;
import org.jeecg.modules.demo.zhengchai.household.service.HouseholdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/household")
public class HouseholdController {

    @Autowired
    private HouseholdService householdService;

    /**
     * 获取户籍信息列表
     * @param page 分页对象
     * @param household 查询条件
     * @return 分页结果
     */
    @GetMapping("/list")
    public ResponseEntity<Page<Household>> list(Page<Household> page, Household household) {
        QueryWrapper<Household> queryWrapper = new QueryWrapper<>(household);
        Page<Household> householdPage = householdService.page(page, queryWrapper);
        return ResponseEntity.ok(householdPage);
    }

    /**
     * 添加户籍信息
     * @param household 户籍信息对象
     * @return 是否添加成功
     */
    @PostMapping("/add")
    public ResponseEntity<Boolean> add(@RequestBody Household household) {
        boolean result = householdService.save(household);
        return ResponseEntity.ok(result);
    }

    /**
     * 修改户籍信息
     * @param household 户籍信息对象
     * @return 是否修改成功
     */
    @PutMapping("/edit")
    public ResponseEntity<Boolean> edit(@RequestBody Household household) {
        boolean result = householdService.updateById(household);
        return ResponseEntity.ok(result);
    }

    /**
     * 删除户籍信息
     * @param id 户籍信息ID
     * @return 是否删除成功
     */
    @DeleteMapping("/delete")
    public ResponseEntity<Boolean> delete(@RequestParam("id") Long id) {
        boolean result = householdService.removeById(id);
        return ResponseEntity.ok(result);
    }

    /**
     * 根据ID查询户籍信息
     * @param id 户籍信息ID
     * @return 户籍信息对象
     */
    @GetMapping("/queryById")
    public ResponseEntity<Household> queryById(@RequestParam("id") Long id) {
        Household household = householdService.getById(id);
        return ResponseEntity.ok(household);
    }
}
